﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
  xmlns:view="clr-namespace:Southridge.View"
  >

    <!--
  *****************************************************************************
  BRUSHES
  *****************************************************************************
  -->

    

    <!--
  *****************************************************************************
  METRICS
  *****************************************************************************
  -->

    <!--
  *****************************************************************************
  ICONS AND IMAGES
  *****************************************************************************
  -->

    <!--
  *****************************************************************************
  SHARED OBJECTS
  *****************************************************************************
  -->

    <!-- Data Converters -->

    <view:BoolToOpacityConverter x:Key="BoolToOpacityConverter" />
    <view:ObjectToTypeName x:Key="ObjectToTypeName" />

    <!--
  *****************************************************************************
  STYLES AND TEMPLATES
  *****************************************************************************
  -->

    <!-- Column Header -->

    <Style x:Key="Style_HeaderGripper" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type dg:DataGridColumnHeader}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="28" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridColumnHeader}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1" Background="{DynamicResource DataGridHeaderSortedBackgroundBrush}" BorderBrush="{DynamicResource DataGridHeaderSortedBorderBrush}" Grid.ColumnSpan="2" />
                        <ContentPresenter Margin="6,3,6,3" VerticalAlignment="Center" />
                        <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" Grid.Column="1" Width="8" Height="6" Fill="White" Margin="0,0,8,0" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                        <Rectangle Width="1" Fill="{DynamicResource DataGridColumnHeaderSeparator1Brush}" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
                        <Rectangle Width="1" Margin="0,0,1,0" Fill="{DynamicResource DataGridColumnHeaderSeparator2Brush}" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
                        <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource Style_HeaderGripper}"/>
                        <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource Style_HeaderGripper}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="SortDirection" Value="{x:Null}">
                            <Setter TargetName="BackgroundBorder" Property="Background" Value="Transparent" />
                            <Setter TargetName="BackgroundBorder" Property="BorderBrush"  Value="Transparent" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource DataGridHeaderMouseOverBackgroundBrush}" />
                            <Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="{DynamicResource DataGridHeaderBorderBrush}" />
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Ascending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Descending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="DisplayIndex" Value="0">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="PART_LeftHeaderGripper"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRowHeader -->

    <Style x:Key="{x:Type dg:DataGridRowHeader}" TargetType="{x:Type dg:DataGridRowHeader}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridRowHeader}">
                    <Border Background="Transparent">
                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridCell -->

    <Style TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                    <Border x:Name="BackgroundBorder" Background="Transparent">
                        <ContentPresenter VerticalAlignment="Center" Margin="4,0,6,0" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRow -->

    <Style x:Key="{x:Type dg:DataGridRow}" TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridRow}">
                    <Border 
              x:Name="DGR_Border"
              Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}"
              SnapsToDevicePixels="True">
                        <dg:SelectiveScrollingGrid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <dg:DataGridCellsPresenter 
                  Grid.Column="1"
                   ItemsPanel="{TemplateBinding ItemsPanel}"
                   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <dg:DataGridRowHeader 
                  dg:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"  
                  Grid.RowSpan="2"
                  Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Row}}"/>
                            <Grid Grid.Column="1" Grid.Row="1" Name="Details" Visibility="Collapsed" Background="Gray">
                            <dg:DataGridDetailsPresenter />
                            </Grid>
                        </dg:SelectiveScrollingGrid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource DataGridSelectedBrush}" />
                            <Setter TargetName="DGR_Border" Property="TextElement.Foreground" Value="{DynamicResource DataGridSelectedForegroundBrush}" />
                            <Setter TargetName="Details" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGrid -->

    <Style x:Key="{x:Type dg:DataGrid}" TargetType="{x:Type dg:DataGrid}">
        <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="AlternatingRowBackground" Value="{DynamicResource DataGridAltRowBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGrid}">
                    <Border Background="{TemplateBinding Background}">
                        <ScrollViewer Focusable="false" Name="DG_ScrollViewer">
                            <ScrollViewer.Template>
                                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Border Grid.ColumnSpan="3" Background="{DynamicResource DataGridHeaderBackgroundBrush}" BorderBrush="{DynamicResource DataGridHeaderBorderBrush}" BorderThickness="0,1" />
                                        <Button 
                        Command="{x:Static dg:DataGrid.SelectAllCommand}" 
                        Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=RowHeaderActualWidth}"
                        Focusable="false"
                        OverridesDefaultStyle="True"
                        Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.All}}">
                                            <Button.Template>
                                                <ControlTemplate TargetType="{x:Type Button}">
                                                    <Grid>
                                                        <Border Background="{DynamicResource DataGridHeaderBackgroundBrush}" BorderBrush="{DynamicResource DataGridHeaderBorderBrush}" BorderThickness="0,1">
                                                            <Path x:Name="Arrow" VerticalAlignment="Bottom" Margin="4" Fill="#3000" Width="11" Height="11" Stretch="Fill" Data="M1,0 L1,1 0,1 z"/>
                                                        </Border>
                                                        <Rectangle Width="1" Fill="{DynamicResource DataGridColumnHeaderSeparator1Brush}" HorizontalAlignment="Right" />
                                                        <Rectangle Width="1" Margin="0,0,1,0" Fill="{DynamicResource DataGridColumnHeaderSeparator2Brush}" HorizontalAlignment="Right" />
                                                    </Grid>
                                                </ControlTemplate>
                                            </Button.Template>
                                        </Button>
                                        <dg:DataGridColumnHeadersPresenter 
                        Grid.Column="1"                         
                        Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Column}}"/>
                        <!-- JAIMER removed from above
                        SourceScrollViewerName="DG_ScrollViewer" -->
                                        <ScrollContentPresenter Grid.Row="1" Grid.ColumnSpan="2" CanContentScroll="{TemplateBinding CanContentScroll}" />
                                        <ScrollBar 
                        Name="PART_VerticalScrollBar"
                        Grid.Row="1" 
                        Grid.Column="2" 
                         Orientation="Vertical"
                         Maximum="{TemplateBinding ScrollableHeight}"
                         ViewportSize="{TemplateBinding ViewportHeight}"
                         Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                        <Grid Grid.Row="2" Grid.Column="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <ScrollBar 
                          Grid.Column="1"
                          Name="PART_HorizontalScrollBar"
                          Orientation="Horizontal"
                          Maximum="{TemplateBinding ScrollableWidth}"
                          ViewportSize="{TemplateBinding ViewportWidth}"
                          Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                          Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </ScrollViewer.Template>
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
        </Style.Triggers>
    </Style>


</ResourceDictionary>